package apiday03.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ForEachDemo {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("语文", 99);
        map.put("数学", 95);
        map.put("物理", 85);
        map.put("政治", 88);
        map.put("英语", 68);
        System.out.println(map);

        //遍历键
        Set<String> keySet = map.keySet();
        keySet.forEach(key -> System.out.println(key));
        //遍历值
        Collection<Integer> values = map.values();
        values.forEach(value -> System.out.println(value));
        //遍历键值对1
        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        entrySet.forEach(e -> System.out.println(e.getKey() + "," + e.getValue()));
        //遍历键值对2
        map.forEach((k, v) -> System.out.println(k + "," + v));
    }
}
